from dataclasses import dataclass, field
from typing import List, Optional
from datetime import timedelta
@dataclass
class UserPerformanceMetrics:
    """用户表现指标数据类 - 五维雷达图评估"""
    user_id: str
    total_questions: int = 0
    solved_questions: int = 0
    solve_rate: float = 0.0
    average_resolution_time: Optional[timedelta] = None
    total_attempts: int = 0
    # 五维评估指标
    efficiency_score: float = 0.0          # 效率能力
    consistency_score: float = 0.0         # 一致性表现
    writeup_quality_score: float = 0.0     # 题解质量
    technical_skill_score: float = 0.0     # 技术能力
    progress_velocity_score: float = 0.0   # 进步速度
    overall_score: float = 0.0
    performance_rank: int = 0
    solved_question_ids: List[str] = field(default_factory=list)
@dataclass
class QuestionDifficultyMetrics:
    """题目难度指标数据类"""
    question_id: str
    pass_rate: float = 0.0
    average_attempts: float = 0.0
    average_resolution_time: Optional[timedelta] = None
    difficulty_level: str = "Unknown"
    difficulty_score: float = 0.0
@dataclass
class OprationChain:
    """操作链数据类"""
    user_id: str
    question_id: str
    actions: List[str] = field(default_factory=list)
@dataclass
class ChatMessage:
    """聊天消息数据类"""
    message_id: str
    user_id: str
    question_id: str
    message_type: str  # "user" or "assistant"
    agent_type: str  # "attack" or "defense"
    content: str
    timestamp: str
    # is_helpful: Optional[bool] = None
    # attack_action: Optional[str] = None  # 攻击行为(仅攻击Agent消息)
    # defense_action: Optional[str] = None  # 防御措施(仅防御Agent消息)
@dataclass
class ChatRecord:
    """聊天记录数据类"""
    user_id: str
    question_id: str
    agent_type: str  # "attack" or "defense"
    messages: List[ChatMessage] = field(default_factory=list)
    total_messages: int = 0
    conversation_duration: Optional[timedelta] = None
    opration_chain= None
    # attack_action: Optional[str] = None  # 攻击行为(仅攻击Agent消息)
    # defense_action: Optional[str] = None  # 防御措施(仅防御Agent消息
    # user_satisfaction: Optional[float] = None
@dataclass
class DefenseAction:
    """防御措施数据类"""
    action_id: str
    description: str
    timestamp: str
    effectiveness: Optional[str] = None  # "effective", "ineffective", "unknown"
@dataclass
class AttackAction:
    """攻击行为数据类"""
    action_id: str
    description: str
    timestamp: str
    success: Optional[str] = None  # "successful", "failed", "unknown"
@dataclass
class DefenseChainData:
    """防御链数据类"""
    user_id: str
    question_id: str
    defense_actions: List[DefenseAction] = field(default_factory=list)
    total_actions: int = 0
@dataclass
class AttackChainData:
    """攻击链数据类（统一格式）"""
    user_id: str
    question_id: str
    attack_actions: List[AttackAction] = field(default_factory=list)
    total_actions: int = 0
